import { defineStore } from "pinia";

export const useCounterStore = defineStore({
  id: "counter",
  persist: true,
  state: () => ({
    counter: 0,
    Arr: [],
    history: [],
    flag: false,
  }),
  getters: {
    // doubleCount: (state) => state.counter * 2,
  },
  actions: {
    // 出的数据
    getArr(obj) {
      // console.log(obj);
      this.Arr = obj;
    },
    // 历史记录数据
    getHistory(val) {
      // console.log(val);
      let index = this.history.findIndex((item) => item == val);
      // console.log(index);
      if (index > -1) {
        this.history.splice(index, 1);
        this.history.unshift(val);
      } else {
        this.history.unshift(val);
      }
    },
    // 历史记录删除
    delAll() {
      this.history = [];
    },
    getToggle(flag) {
      console.log(flag);
      this.flag = flag;
    },
  },
});
